<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.Locale" %>
<%--
  Created by IntelliJ IDEA.
  User: lzy
  Date: 2018/8/24
  Time: 9:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>locale</title>
</head>
<%
    Date date = new Date();
    request.setAttribute("date", date);
    request.setAttribute("salary", 12345.6);

    String code = request.getParameter("code");
    if (code != null) {
        if ("en".equals(code)) {
            session.setAttribute("locale", Locale.US);
        } else if ("ch".equals(code)) {
            session.setAttribute("locale", Locale.CHINA);
        }
    }
%>
<%--<fmt:bundle basename="i18n">
    <fmt:message key="date"/>:
    <fmt:formatDate value="${date}"/>,
    <fmt:message key="salary"/>:
    <fmt:formatNumber value="${salary}"/>
</fmt:bundle>
<br/><br/>--%>
<c:if test="${sessionScope.locale !=null}">
    <fmt:setLocale value="${sessionScope.locale}"/>
</c:if>
<fmt:setBundle basename="i18n"/>
<fmt:message key="date"/>:
<fmt:formatDate value="${date}" dateStyle="FULL"/>,
<fmt:message key="salary"/>:
<fmt:formatNumber value="${salary}" type="currency"/>
<br/><br/>
<a href="index.jsp?code=en">English</a>
<a href="index.jsp?code=ch">中文</a>

</body>
</html>
